package cn.itcast.reggie.utils;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;
/**
 * 短信测试工具类
 */
public class SMSTestUtil {

    public static void sendSms(String mobile){
        try{

        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId("LTAI5tHMVjWbRdNvGHyJRyNT")
                // 您的AccessKey Secret
                .setAccessKeySecret("WTXlOC3xXdimsux6dA2DTpaq1ta6I2");
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        com.aliyun.dysmsapi20170525.Client client = new com.aliyun.dysmsapi20170525.Client(config);
        com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setSignName("阿里云短信测试")
                .setTemplateCode("SMS_154950909")
                .setPhoneNumbers(mobile)
                .setTemplateParam("{\"code\":\"1234\"}");
        RuntimeOptions runtime = new RuntimeOptions();
        // 复制代码运行请自行打印 API 的返回值
        SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
        System.out.println(sendSmsResponse.getBody().getCode());

        }catch (Exception ex){
            ex.printStackTrace();
            System.out.println("短信发送失败");
        }
    }

    public static void main(String[] args){
        //验证码
        SMSTestUtil.sendSms("17629308684");
    }
}
